package xiao_jin.fantasy.core.init;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.passive.AllayEntity;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import xiao_jin.fantasy.core.common.entity.entityType.mob.StrangeSquidEntity;

import static xiao_jin.fantasy.Fantasy.MOD_ID;

public class FantasyEntity implements ModInitializer {
    public static final EntityType<StrangeSquidEntity> STRANGE_SQUID = register(
            "strange_squid",
            EntityType.Builder.create(StrangeSquidEntity::new, SpawnGroup.WATER_CREATURE)
                    .dimensions(0.8F, 0.8F)
                    .eyeHeight(0.4F)
                    .maxTrackingRange(16)
    );
    public static final EntityType<AllayEntity> ALLAY = register(
            "allay",
            EntityType.Builder.create(AllayEntity::new, SpawnGroup.CREATURE)
                    .dimensions(0.35F, 0.6F)
                    .eyeHeight(0.36F)
                    .vehicleAttachment(0.04F)
                    .maxTrackingRange(8)
                    .trackingTickInterval(2)
    );
    public static <T extends Entity> EntityType<T> register(RegistryKey<EntityType<?>> key, EntityType.Builder<T> type) {
        return Registry.register(Registries.ENTITY_TYPE, key, type.build(key));
    }

    public static RegistryKey<EntityType<?>> keyOf(String id) {
        return RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of(MOD_ID, id));
    }

    public static <T extends Entity> EntityType<T> register(String id, EntityType.Builder<T> type) {
        return register(keyOf(id), type);
    }

    @Override
    public void onInitialize() {
        FabricDefaultAttributeRegistry.register(STRANGE_SQUID, StrangeSquidEntity.createMobAttributes());
    }
}
